﻿function get_Pages_Html(){
  var htmlstr='<table id="Grid_Pages" style="width:auto;height:auto"></table><div id="addPagesdiv" style="display:none"></div><div id="edtPagesdiv" style="display:none"></div>';
  return htmlstr;
}
function getadd_Pages_Html(){
  var htmlstr='<div id="AddDlg_Pages" title="添加记录" icon="icon-window" style="padding:5px;background:#fafafa">';
  htmlstr=htmlstr+'<div class="easyui-layout" fit="true">';
  htmlstr=htmlstr+'<div region="center" border="false" style="padding:10px;background:#fff;border:1px solid #ccc;">';
  htmlstr=htmlstr+'<table width="450" border="0" class="dtable" align="center" cellpadding="4" cellspacing="0">';
  htmlstr=htmlstr+'<tr><td width="200"> 页面标题 </td>';
  htmlstr=htmlstr+'<td><input type="text" name="add_Title" id="add_Title" /></td></tr>';
  htmlstr=htmlstr+'<tr><td width="200"> 页面关键字 </td>';
  htmlstr=htmlstr+'<td><input type="text" name="add_HtmKey" id="add_HtmKey" /></td></tr>';
  htmlstr=htmlstr+'<tr><td width="200"> 页面名称 </td>';
  htmlstr=htmlstr+'<td><input type="text" name="add_Name" id="add_Name" /></td></tr>';
  htmlstr=htmlstr+'<tr><td width="200"> 页面内容 </td>';
  htmlstr=htmlstr+'<td><input type="text" name="add_HtmText" id="add_HtmText" /></td></tr>';
  htmlstr=htmlstr+'<tr><td width="200"> 文件名 </td>';
  htmlstr=htmlstr+'<td><input type="text" name="add_FileName" id="add_FileName" /></td></tr>';htmlstr=htmlstr+'</table></div><div region="south" border="false" style="text-align:right;padding-top:4px;height:30px;line-height:30px;">';
  htmlstr=htmlstr+'<a icon="icon-ok" id="addbt_Pages" href="javascript:void(0)" onclick="Add_Pages()"> 添 加 </a>';
  htmlstr=htmlstr+'</div></div>';
  return htmlstr;
}
function getedt_Pages_Html(){
  var htmlstr='<div id="EditDlg_Pages" title="修改记录" icon="icon-window" style="padding:5px;background:#fafafa">';
  htmlstr=htmlstr+'<div class="easyui-layout" fit="true">';
  htmlstr=htmlstr+'<div region="center" border="false" style="padding:10px;background:#fff;border:1px solid #ccc;">';
  htmlstr=htmlstr+'<table width="450" border="0" class="dtable" align="center" cellpadding="4" cellspacing="0">';
  htmlstr=htmlstr+'<tr><td width="200"> 页面标识 </td>';
  htmlstr=htmlstr+'<td><input type="text" name="add_PageId" id="edt_PageId" /></td></tr>';
  htmlstr=htmlstr+'<tr><td width="200"> 页面标题 </td>';
  htmlstr=htmlstr+'<td><input type="text" name="add_Title" id="edt_Title" /></td></tr>';
  htmlstr=htmlstr+'<tr><td width="200"> 页面关键字 </td>';
  htmlstr=htmlstr+'<td><input type="text" name="add_HtmKey" id="edt_HtmKey" /></td></tr>';
  htmlstr=htmlstr+'<tr><td width="200"> 页面名称 </td>';
  htmlstr=htmlstr+'<td><input type="text" name="add_Name" id="edt_Name" /></td></tr>';
  htmlstr=htmlstr+'<tr><td width="200"> 页面内容 </td>';
  htmlstr=htmlstr+'<td><input type="text" name="add_HtmText" id="edt_HtmText" /></td></tr>';
  htmlstr=htmlstr+'<tr><td width="200"> 文件名 </td>';
  htmlstr=htmlstr+'<td><input type="text" name="add_FileName" id="edt_FileName" /></td></tr>';htmlstr=htmlstr+'</table></div><div region="south" border="false" style="text-align:right;padding-top:4px;height:30px;line-height:30px;">';
  htmlstr=htmlstr+'<a icon="icon-ok" id="edtbt_Pages" href="javascript:void(0)" onclick="Edit_Pages()"> 修 改 </a>';
  htmlstr=htmlstr+'</div></div>';
  return htmlstr;
}
function Add_Pages_Tab(tabname){
  if(!$('#ttab').tabs('exists',tabname)){
	$('#ttab').tabs('add',{
		title:tabname,
		cache:false,
		closable:true,
		content:get_Pages_Html()
	  });
	var gridht = $('body').layout('panel','center').panel('options').height - 58;
	$('#Grid_Pages').datagrid({
	  border:false,
	  nowrap: false,
	  striped: true,
	  collapsible:true,
	  url:'/Data/Pages.ashx',
	  method:'get',
	  height:gridht,
	  queryParams:{type:"0"},
	  fitColumns:true,
	  loadMsg:'正在读取数据,请稍候...',
	  singleSelect:true,
	  columns:[[
		{field:'PageId',checkbox:true},
		{field:'Title',title:'页面标题',width:80},
		{field:'HtmKey',title:'页面关键字',width:80},
		{field:'Name',title:'页面名称',width:80},
		{field:'HtmText',title:'页面内容',width:80},
		{field:'FileName',title:'文件名',width:80}]],
	  pagination:true,
	  rownumbers:true,
	  toolbar:[{
		id:'btn_Pages_add',
		text:'添加',
		iconCls:'icon-add',
		handler:function(){
		  ShowPagesAddFrom();}
		},'-',{
		id:'btn_Pages_edit',
		text:'修改',
		iconCls:'icon-edit',
		handler:function(){
		  GetOne_Pages();}
		},'-',{
		id:'btn_Pages_del',
		text:'删除',
		iconCls:'icon-remove',
		handler:function(){
		 Del_Pages();}
	  }],
	  onLoadError:function(er){
		  $.messager.alert('错误','可能无查看权限,无法加载数据!','error');
	  }
	});
  }else{
	$('#ttab').tabs('select',tabname);
  }
}
function ShowPagesAddFrom(){
  $('#addPagesdiv').html(getadd_Pages_Html());
  $('#AddDlg_Pages').window({
	  title: '添加',
	  width: 600,
	  modal: true,
	  shadow: true,
	  closed: true,
	  height: 400
  });
  $('#addbt_Pages').linkbutton({iconCls:"icon-ok"});
  $('#AddDlg_Pages').window('open');
}
function ShowPagesEdtFrom(){
  $('#edtPagesdiv').html(getedt_Pages_Html());
}
function Add_Pages(){
  $.get("/Data/Pages.ashx",{type:2,Title:$('#add_Title').val(),HtmKey:$('#add_HtmKey').val(),Name:$('#add_Name').val(),HtmText:$('#add_HtmText').val(),FileName:$('#add_FileName').val()},
  function(data){
    $('#AddDlg_Pages').window('close');
	$('#Grid_Pages').datagrid("reload");
  });
}
function GetOne_Pages(){
  var getid=0;
  var selected = $('#Grid_Pages').datagrid('getSelected');
  if (selected){
    getid=selected.PageId;
	$.getJSON("/Data/Pages.ashx",{type:1,id:getid},
	function(data){
			ShowPagesEdtFrom();
			$('#EditDlg_Pages').window({
				title: 'Edit Pages',
				width: 600,
				modal: true,
				shadow: true,
				closed: true,
				height: 300
				});
			$('#EditDlg_Pages').window('open');
			$('#edtbt_Pages').linkbutton({iconCls:"icon-ok"});
						$('#edt_PageId').val(data.model.PageId);
						$('#edt_Title').val(data.model.Title);
						$('#edt_HtmKey').val(data.model.HtmKey);
						$('#edt_Name').val(data.model.Name);
						$('#edt_HtmText').val(data.model.HtmText);
						$('#edt_FileName').val(data.model.FileName);
			
      });
	}else{
	        $.messager.show({
				title:'提示',
				msg:'没有选择任何记录.',
				timeout:3000,
				showType:'slide'
			});
	}
}
function Edit_Pages(){
  $.get("/Data/Pages.ashx",{type:4,PageId:$('#edt_PageId').val(),Title:$('#edt_Title').val(),HtmKey:$('#edt_HtmKey').val(),Name:$('#edt_Name').val(),HtmText:$('#edt_HtmText').val(),FileName:$('#edt_FileName').val()},
  function(data){
    $('#EditDlg_Pages').window('close');
	$('#Grid_Pages').datagrid("reload");
  }); 
}
function Del_Pages(){
  var getid=0;
  var selected = $('#Grid_Pages').datagrid('getSelected');
  if(!selected){
	        $.messager.show({
				title:'提示',
				msg:'没有选择任何记录.',
				timeout:3000,
				showType:'slide'
			});
			return;
  }
  
  getid=selected.PageId;
  $.messager.confirm('确认删除', '请确认是否进行此操作?', function(r){
	  if(r){
			$.get("/Data/Pages.ashx",{type:3,id:getid},
			function(data){
				$.messager.show({
					title:'提示',
					msg:'已删除数据.',
					timeout:3000,
					showType:'slide'
				});
				$('#Grid_Pages').datagrid("reload");
			}); 
		  }
  }); 
} 
  